<%--
  Created by IntelliJ IDEA.
  User: Rainh
  Date: 2020/4/26
  Time: 18:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>欢迎来到学生管理系统页面</title>
</head>
<script src="js/jquery-3.5.0.min.js"></script>

<script>
    //登录验证
    $(function () {
        //登录点击函数
        $("#btn_login").click(function () {
            //异步请求
            $.ajax({
                url:"ajaxLoginController",
                type:"post",
                contentType:"application/json;charset=UTF-8",
                data:JSON.stringify({
                    account:document.getElementById("account").value,
                    password:document.getElementById("password").value
                }),
                dataType:"json",
                success:function (data) {
                    //如果账号密码错误
                    if(!data){
                        $("#login_message").text("登录失败，请检查用户名和密码:");
                    }else {
                        window.location.href="indexController";
                    }
                },
                error:function (e) {
                    alert("出错啦。。。，请刷新页面");
                }
            });
        })
    });

</script>
<body>

    <a href="/hello">点我进入hello的controller</a>
    <a href="/upload.jsp">点我进入上传文件页面</a>

<%--    <form action="loginServlet" method="post">--%>
    <form action="/loginController" method="post">

        <table width="800" align="center">
            <caption>请输入账号和密码</caption>
            <tr>
                <td>账号</td>
                <td>
                    <input type="text" name="account" id="account">
                </td>
            </tr>
            <tr>
                <td>密码</td>
                <td>
                    <input type="password" name="password" id="password">
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <span id="login_message" style="color:#ff1751"></span>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <input type="reset" value="重新填写">
                    <input type="button" value="登录" id="btn_login" >
<%--                    <input type="button" value="登录" onclick="btn_login()" >--%>
                </td>
            </tr>

        </table>

    </form>

</body>
</html>
